#include "Key.h"

#include "Player.h"


Key::Key(int x, int y):
	Pickup(x, y),
	keyType(Player::InventoryItem_Key)
{
}


Key::Key(int x, int y, Player::InventoryItem keyType):
	Pickup(x, y),
	keyType(keyType)
{
}


Key::~Key()
{
}


void Key::handleCollision(GameObject* gameObject)
{
	if (gameObject->getType() == Type_Player)
	{
		static_cast<Player*>(gameObject)->addToInventory(keyType);
		destroy();
	}
}


void Key::drawObject(int row, int col) const
{
	std::vector<drawPoint> points;

	if (keyType == Player::InventoryItem_GateKey)
		setColor(1.0f, 0.0f, 1.0f);

	// Top handle.
	points.push_back(drawPoint(col + 0.3, row + 0.0, 0));
	points.push_back(drawPoint(col + 0.7, row + 0.0, 0));
	points.push_back(drawPoint(col + 0.7, row + 0.4, 0));
	points.push_back(drawPoint(col + 0.3, row + 0.4, 0));

	// Body.
	points.push_back(drawPoint(col + 0.45, row + 0.2, 0));
	points.push_back(drawPoint(col + 0.55, row + 0.2, 0));
	points.push_back(drawPoint(col + 0.55, row + 1.0, 0));
	points.push_back(drawPoint(col + 0.45, row + 1.0, 0));

	// Upper tooth.
	points.push_back(drawPoint(col + 0.3, row + 0.7, 0));
	points.push_back(drawPoint(col + 0.5, row + 0.7, 0));
	points.push_back(drawPoint(col + 0.5, row + 0.8, 0));
	points.push_back(drawPoint(col + 0.3, row + 0.8, 0));

	// Lower tooth.
	points.push_back(drawPoint(col + 0.3, row + 0.9, 0));
	points.push_back(drawPoint(col + 0.5, row + 0.9, 0));
	points.push_back(drawPoint(col + 0.5, row + 1.0, 0));
	points.push_back(drawPoint(col + 0.3, row + 1.0, 0));

	drawInMode(GL_QUADS, points);
	points.clear();

	// Top handle gap.
	setColor(0,0,0);
	
	points.push_back(drawPoint(col + 0.4 , row + 0.125, 0));
	points.push_back(drawPoint(col + 0.55, row + 0.125, 0));
	points.push_back(drawPoint(col + 0.55, row + 0.3, 0));
	points.push_back(drawPoint(col + 0.4 , row + 0.3, 0));

	drawInMode(GL_QUADS, points);
	points.clear();
}